#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* getIntersectionNode(ListNode* headA, ListNode* headB)
    {
        ListNode* cur_A = headA, * cur_B = headB;
        while (cur_A != cur_B)
        {
            cur_A = cur_A == nullptr ? headB : cur_A->next;
            cur_B = cur_B == nullptr ? headA : cur_B->next;
        }
        return cur_A;

    }
};